package com.bo.usermana.entity;

import java.time.LocalDate;
import java.util.Objects;

import javax.persistence.AttributeConverter;
import javax.persistence.Convert;

import com.fasterxml.jackson.annotation.JsonFormat;

import lombok.Data;

@Data
public class UserInfo {
	private Long uid;
	private String IDNumber;
	@Convert(converter = GenderConvert.class)
	private Byte gender;
	@JsonFormat(pattern = "MM/dd/yyyy")
	private LocalDate birthday; 
	private String address;
	private String hobby;
	private String appcode;

	public static class GenderConvert implements AttributeConverter<String, Byte> {

		@Override
		public Byte convertToDatabaseColumn(String attribute) {
			return Objects.equals(attribute, "male") ? (byte) 1 : (byte) 0;
		}

		@Override
		public String convertToEntityAttribute(Byte dbData) {
			return dbData == 1 ? "male" : "famale";
		}

	}
}
